<?php

abstract class controller_abstract extends controller
{
	protected $app, $json, $template, $view, $config, $system;

    function __construct(& $app)
    {
        parent::__construct();

		$this->app = $app;
		$this->config = config::get('config');
		$this->json = & factory::json();
		
		if ($app->client === 'admin')
		{
			$this->view = & factory::view($app->app);
		    $this->view->assign('CONFIG', & $this->config);
		}

		$this->template = & factory::template($app->app);
		$this->template->assign('CONFIG', & $this->config);
    }
    
    public function execute()
    {
    	if ($this->action_exists($this->app->action))
    	{
    		$response = call_user_func_array(array($this, $this->app->action), $this->app->args);
    	}
    	else 
    	{
    		$this->_action_not_defined($this->app->action);
    	}
        return $response;
    }
    
    protected function _action_not_defined($action)
    {
    	$this->showmessage("<font color='red'>$action</font> 动作不存在");
    }
    
}